<?php


if (!function_exists('strToUcWords')){
    /**
     * 将英文字符串 [hello world, hello-world, hello_world, hello,world] 转成 HelloWorld
     * @param string $word
     * @param string $replace
     * @return string
     */
    function strToUcWords(string $word, string $replace = ""): string
    {
        $word = str_replace(["-","_",","]," ",$word);
        if ($replace){
            $word = str_replace($replace," ",$word);
        }
        return str_replace(" ","",ucwords($word));
    }
}

if (!function_exists('isSfcView')){
    /**
     * 是否sfc单文件视图
     * @param string $view
     * @return bool
     */
    function isSfcView(string $view = ""): bool
    {
        $pattern1 = "/<script(.*?)>(.*?)export(.*?)default(.*?){(.*?)}(.*?)<\/script>/s";
        $pattern2 = "/<script(.*?)setup(.*?)>(.*?)<\/script>/s";
        $pattern3 = "/<template(.*?)>(.*?)<\/template>/s";
        $check1 = preg_match($pattern1, $view);
        $check2 = preg_match($pattern2, $view);
        $check3 = preg_match($pattern3, $view);
        if (($check1&&$check3)||($check2&&$check3)){
            return true;
        }
        if ($check3&&!$check1&&!$check2){
            return true;
        }
        return false;
    }
}




